package com.heima.minio.test;

import com.heima.minio.MinioApplication;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.errors.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2022/1/5 19:02
 */

@SpringBootTest(classes = MinioApplication.class)
@RunWith(SpringRunner.class)
public class MinioTest1 {

    public static void main(String[] args) {
        try {
            FileInputStream fileInputStream = new FileInputStream("C:/Users/LGL/Desktop/list.html");
            // 创建minio链接客户端
            MinioClient minioClient = MinioClient.builder()
                    .credentials("minio", "minio123")
                    .endpoint("http://192.168.200.130:9000").build();
            // 上传
            PutObjectArgs putObjectArgs = PutObjectArgs.builder()
                    .object("list.html")  // 文件名
                    .contentType("text/html") // 文件类型
                    .bucket("news")  // 桶名
                    .stream(fileInputStream, fileInputStream.available(), -1)  // 文件流
                    .build();

            minioClient.putObject(putObjectArgs);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
